﻿using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;

namespace LengthAiCalculate
{
    public partial class ServerInfo : Form
    {
        public ServerInfo()
        {
            InitializeComponent();
        }

        public static List<IPAddress> GetLocalIP()
        {
            List<IPAddress> ip = new List<IPAddress>();
            try
            {
                IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
                foreach (IPAddress item in IpEntry.AddressList)
                {
                    if (item.AddressFamily == AddressFamily.InterNetwork)
                    {
                        ip.Add(item);
                    }
                }
            }
            catch { }
            return ip;
        }

        private void ServerInfo_Load(object sender, System.EventArgs e)
        {
            listBox1.Items.Clear();
            foreach (var item in GetLocalIP())
            {
                listBox1.Items.Add(item.ToString());
            }
            textBox1.Text = SysInit.SocketPort.ToString();
            textBox1.Enabled = false;
            if (SysInit.SocketServer.SocketIsOK)
            {
                label4.Text = "已启动";
                label4.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                label4.Text = "未启动";
                label4.ForeColor = System.Drawing.Color.Red;
            }
            foreach (var item in SysInit.SocketServer.ClientDic)
            {
                listBox2.Items.Add(item.Key);
            }
        }
    }
}